﻿using System;
using System.Collections.Generic;
using System.Web;
using Moq;

namespace Steve.TestHelper
{
    public static class MockWebHelpers
    {
        public static HttpContextBase MockHttpContext()
        {
            var context = new Mock<HttpContextBase>(MockBehavior.Strict);
            var request = new Mock<HttpRequestBase>(MockBehavior.Strict);
            var response = new Mock<HttpResponseBase>(MockBehavior.Strict);
            var session = new Mock<HttpSessionStateBase>(MockBehavior.Strict);
            var server = new Mock<HttpServerUtilityBase>(MockBehavior.Strict);

            context.Setup(ctx => ctx.Request).Returns(request.Object);
            context.Setup(ctx => ctx.Response).Returns(response.Object);
            context.Setup(ctx => ctx.Session).Returns(session.Object);
            context.Setup(ctx => ctx.Server).Returns(server.Object);
            context.Setup(ctx => ctx.Items).Returns(new Dictionary<object, object>());

            return context.Object;
        }

        public static void Mock<T>(this T mocked, Action<Mock<T>> setupAction) where T : class
        {
            setupAction(Moq.Mock<T>.Get(mocked));
        }

    }
}
